package com.snow.useviewdemo.function2.service;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

import com.snow.useviewdemo.MainActivity;
import com.snow.useviewdemo.R;
import com.snow.useviewdemo.base.BaseActivity;
import com.snow.useviewdemo.databinding.ActCheckOServiceBinding;

/**
 * Created by zhaoyingtao
 * Date: 2020/8/12
 * Describe:验证8.0以后启动service的问题
 */
public class CheckOServiceActivity extends BaseActivity<ActCheckOServiceBinding> {
    private static final String TAG = CheckOServiceActivity.class.getSimpleName();

    @Override
    protected int getLayoutId() {
        return R.layout.act_check_o_service;
    }

    @Override
    protected void setViewData(Bundle savedInstanceState) {
        mBinding.btn001.setOnClickListener(v -> {
            Log.d(TAG, "start service");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                Intent intent = new Intent(CheckOServiceActivity.this, MyOService.class);
                intent.putExtra("type", 1);
                startForegroundService(intent);
            }
        });
        mBinding.btn002.setOnClickListener(v -> {
            Log.d(TAG, "start service");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                Intent intent = new Intent(CheckOServiceActivity.this, MyOService.class);
                intent.putExtra("type", 2);
                startForegroundService(intent);
            }
        });
    }
}
